package com.mobvoi.ros;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.TextView;


import androidx.annotation.Nullable;
import static com.mobvoi.ros.BaseApplication.uartServiceStart;

public class MainActivity extends Activity implements View.OnClickListener {

    private TextView tvStart;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        tvStart = findViewById(R.id.tv_start);
        tvStart.setOnClickListener(this);

    }

    @Override
    protected void onResume() {
        super.onResume();
        Log.d("uartservice","MainActivity onResume");
        Log.d("uartservice","uartServiceStart:"+uartServiceStart);
        if(uartServiceStart)
        {
            tvStart.setText("服务已启动");
        }
        else
        {
            tvStart.setText("点击开启服务");
        }
    }

    @Override
    protected void onPause() {
        super.onPause();

    }

    public void exit(View view) {
        Intent serviceIntent = new Intent(this, CoreService.class);
        stopService(serviceIntent);
        finishAndRemoveTask();
        android.os.Process.killProcess(android.os.Process.myPid());
        System.exit(0);
        uartServiceStart=false;
    }

    @Override
    public void onClick(View view) {
        switch(view.getId())
        {
            case R.id.tv_start:
            {
                if(!uartServiceStart)
                {
                    uartServiceStart=true;
                    Intent serviceIntent = new Intent(this, CoreService.class);
                    startService(serviceIntent);
                    tvStart.setText("服务已启动");

                }
                break;
            }
            default:
                break;
        }
    }
}
